//
//  LBCourseYinpinCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/3.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBCourseYinpinCell.h"

@implementation LBCourseYinpinCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifferCell = @"LBCourseYinpinCell";
    LBCourseYinpinCell *cell = [tableView dequeueReusableCellWithIdentifier:identifferCell];
    if (!cell) {
        cell = [[LBCourseYinpinCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifferCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
    return cell;
}
- (void)setupUI{
    
    self.icon = [[UIImageView alloc] init];
    self.icon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    self.icon.layer.cornerRadius = 5;
    self.icon.layer.masksToBounds = YES;
    [self.contentView addSubview:self.icon];
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(76*kScaleFit, 46*kScaleFit));
        make.centerY.mas_equalTo(self.contentView);
    }];
    self.titleLab = [UILabel labelWithText:@"课时1 0a-Unit1" andTextColor:rgb(51,51,51) andName:nil andFontSize:15*kScaleFit];
    
    [self.contentView addSubview:self.titleLab];
    [self.titleLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.centerY.mas_equalTo(self.contentView);
        make.width.lessThanOrEqualTo(175*kScaleFit);
    }];
    
    self.timeLab = [UILabel labelWithText:@"50:11:21" andTextColor:rgb(102,102,102) andName:nil andFontSize:14*kScaleFit];
    self.timeLab.numberOfLines = 0;
    [self.contentView addSubview:self.timeLab];
    [self.timeLab makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(-15*kScaleFit);
        
    }];
    //
    self.videoIcon = [[UIImageView alloc] init];
    self.videoIcon.image = [UIImage imageNamed:@"wk_audio"];//wk_vedio_s
    [self.contentView addSubview:self.videoIcon];
    [self.videoIcon makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.timeLab.mas_left).mas_equalTo(-5*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(16*kScaleFit, 10*kScaleFit));
        make.centerY.mas_equalTo(self.contentView);
    }];
}
- (void)setModel:(LBCourseHourOutputDTOList *)model{
    _model = model;
//    self.titleLab.text = model.videoLength;
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,model.videoImage];
    [self.icon sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"wk_audio"]];
    self.titleLab.text = model.hourName;
    self.timeLab.text = model.videoLength;


}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    if (selected) {
        self.timeLab.textColor = [UIColor colorWithRed:233.f/255.f green:84.f/255.f blue:18.f/255.f alpha:1];
        self.titleLab.textColor = [UIColor colorWithRed:233.f/255.f green:84.f/255.f blue:18.f/255.f alpha:1];
        self.videoIcon.image = [UIImage imageNamed:@"wk_audio_s"];
    }else
    {
        self.timeLab.textColor =  [UIColor colorWithRed:102.f/255.f green:102.f/255.f blue:102.f/255.f alpha:1];
        self.titleLab.textColor =  [UIColor colorWithRed:102.f/255.f green:102.f/255.f blue:102.f/255.f alpha:1];
        self.videoIcon.image = [UIImage imageNamed:@"wk_audio"];
    }
    
}
@end
